package com.hfb.mashibing.alip8.designpattern._01singleton;

/**
 * 饿汉式
 * 类加载到内存后就实例化一个单例，jvm 保证线程安全
 * 简单实用，推荐！
 * Class.forName("")
 *
 * 唯一缺点: 加载即实例化，浪费内存
 */
public class Mgr01 {

    private static final Mgr01 INSTANCE = new Mgr01();

    private Mgr01() {}

    public static Mgr01 getInstance() {
        return INSTANCE;
    }

    public static void main(String[] args) {
        Mgr01 m1 = Mgr01.getInstance();
        Mgr01 m2 = Mgr01.getInstance();
        System.out.println(m1 == m2);
    }
}
